from dbusmgr import SetSystemSignalCallback

on_connect = []
on_disconnect = []
is_connected = False

def IsConnected():
  global is_connected
  return is_connected

def AddCallback(connect, disconnect):
  global on_connect
  global on_disconnect

  if connect:
    on_connect.append(connect)
  if disconnect:
    on_disconnect.append(disconnect)

def OnChargerDisconnected(**args):
  global is_connected
  global on_disconnect
  is_connected = False
  for cb in on_disconnect:
    cb()

def OnChargerConnected(**args):
  global is_connected
  global on_connect
  is_connected = True
  for cb in on_connect:
    cb()

SetSystemSignalCallback("charger_connected", "com.nokia.bme.signal",
    OnChargerConnected)

SetSystemSignalCallback("charger_disconnected", "com.nokia.bme.signal",
    OnChargerDisconnected)
